﻿using System.Collections.Generic;

namespace Spider.Visited
{
    public  class DicVisited : IVisited
    {
        private static Dictionary<string, VisitedData> _visited = new Dictionary<string, VisitedData>();
        /// <summary>
        /// 已访问数量
        /// </summary>
        public int GetCount()
        {
             return _visited.Count; 
        }
        /// <summary>
        /// 将Url添加到Hashish
        /// </summary>
        /// <param name="url"></param>
        /// <param name="data"></param>
        public  void AddUrl(string url, VisitedData data)
        {
            if (!_visited.ContainsKey(url))
                _visited.Add(url, data);
        }
        /// <summary>
        /// 判断url是否已经存在于Hashish
        /// </summary>
        /// <param name="url"></param>

        public  bool ContainUrl(string url)
        {
            if (_visited.ContainsKey(url))
            {
                return true;
            }
            else
            {
                return false;
            }

        }
        /// <summary>
        /// 从Hashish中获取Url数据
        /// </summary>
        /// <param name="url"></param>
        public  VisitedData GetUrl(string url)
        {
            if (_visited.ContainsKey(url))
            {
                return _visited[url];
            }
            else
            {
                return null;
            }

        }
        /// <summary>
        /// 从Hashish中移除Url数据
        /// </summary>
        /// <param name="url"></param>
        public  void RemoveUrl(string url)
        {
            if (_visited.ContainsKey(url))
                _visited.Remove(url);
        }
    }
}
